home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / prodpack.zip / DB4PPSRC.EXE / _FXUSEIT.PRG < prev    next >
Text File  |  1993-05-04  |  6KB  |  198 lines

  1. *' $Header:   E:/test/sysproc/doc/_fxuseit.prv   1.1   12 Aug 1992 16:55:56   Bill Ramos  $
  2. PROCEDURE _fxUseIt
  3. PARAMETERS pc_file, pl_useok, pl_scbatt
  4. *---------------------------------------------------------------------
  5. * NAME
  6. *   _fxUseIt - Use the correct DBF or View based on extensions
  7. *
  8. * DESCRIPTION
  9. *   The _fxUseit procedure is a high level program that will
  10. *   do the following:
  11. *     Determine the DBF or view to use based on the <pc_file>
  12. *     If there is no DBF open, open the catalog DBF or view.
  13. *     Otherwise, if the open DBF or view is not the catalog DBF or view,
  14. *       Display the Current view vs catalog DBF or view box
  15. *       Use one of the two files
  16. *     If _fxUseIt could not open the DBF or view, then <pl_useok>
  17. *     is set to .F., otherwise it's .F.
  18. *
  19. * SYNOPSIS
  20. *   DO _fxUseIt WITH <pc_file>, <pl_useok>
  21. *
  22. * PARAMETERS
  23. *   pc_file   = target SCR file
  24. *   pl_useok  = .T. if DBF or view used ok, else .F.  It's value is
  25. *               forced to .F. at the start of the procedure
  26. *   pl_scbatt = SCB file attached, do not call _CatWhich
  27. *
  28. * EXAMPLE
  29. *   *-- Put the correct DBF in view based on the SCR linking CODE
  30. *   ok = .F.                            && Set the open DBF or view flag
  31. *   DO _fxUseIt WITH "goods.scr", ok    && Try and open the file
  32. *   IF .NOT. ok                         && If the open failed
  33. *     ...                               && Handle the failure here
  34. *   ENDIF
  35. *
  36. * LIMITATIONS
  37. *   Talk must be off, Fields must be off, Exact must be on
  38. *
  39. * DEPENDENCIES
  40. *   Calls:  _FileRoot(), _FileType(), _Cat4Dbf, _OpenDbf, _CatWhich
  41. *   Called by:  _FxEntry
  42. *
  43. * VARIABLES
  44. *   lc_scrname  = Root name for the current SCR file name
  45. *   lc_scrext   = Extension for SCR file name, should always be SCR
  46. *   ll_isview   = If the file related to the SCR name in the catalog
  47. *                 as a QBE file, then it's set to .T., else .F.
  48. *   lc_dbf2use  = Name of the DBF or QBE file to use based on the current
  49. *                 file open, or the user's selection in _Cat4Dbf.  If the
  50. *                 value is blank, there is no matching DBF or QBE in the
  51. *                 catalog, or the user pressed Escape in the
  52. *                 "Current view" menu.
  53. *   lc_catdbf   = Root name for the Name of the DBF or QBE file to use.
  54. *   ll_usedby   = Set by _CatWhich, if .T., then use the associated
  55. *                 catalog DBF or QBE file.  If .F., then use the
  56. *                 current DBF or QBE.
  57. *   ll_esc      = Set by _CatWhich, if .T., then the user pressed the
  58. *                 Escape key in the "Current view" menu.
  59. *   lc_view     = Name of VIEW if any, blank if not
  60. *   ln_vrecno   = Record number in the view if a view is active, else
  61. *                 the value is not defined
  62. *---------------------------------------------------------------------
  63.   PRIVATE lc_scrname, lc_scrext, ll_isview, lc_dbf2use, ;
  64.           lc_catdbf, ll_usedby, ll_esc, lc_view
  65.  
  66.   lc_scrname = _FileRoot( pc_file )
  67.   lc_scrext  = _FileType( pc_file )
  68.   ll_isview = .F.                       && Assume match file is DBF
  69.   pl_useok = .F.                        && Assume the file is not used
  70.   lc_view = SET( "VIEW" )
  71.   IF .NOT. ISBLANK( lc_view )
  72.     ln_vrecno = RECNO()
  73.   ENDIF
  74.  
  75.   *-- Get the DBF or QBE for the Design file
  76.   lc_dbf2use = ""                       && Preset the DBF or view to use
  77.   DO _Cat4Dbf WITH ( lc_scrname + "." + lc_scrext ), ;
  78.                     lc_dbf2use, ;
  79.                     ll_isview, ;
  80.                     .F.
  81.  
  82.   IF .NOT. ISBLANK( lc_view )
  83.  
  84.     SET VIEW TO &lc_view
  85.  
  86.     IF ln_vrecno > 0
  87.       GO ln_vrecno
  88.     ENDIF
  89.  
  90.   ENDIF
  91.  
  92.   lc_catdbf = _FileRoot( lc_dbf2use )   && Trim up for alias match
  93.  
  94.   IF .NOT. ISBLANK( lc_dbf2use )        && If a DBF or view matched SCR file
  95.  
  96.     IF ISBLANK( DBF() )                 && If no DBF is open
  97.  
  98.       IF ll_isview                      && If this a QBE match
  99.  
  100.         SET VIEW TO ( lc_dbf2use )      && Open the view
  101.         pl_useok = .T.                  && Set the open flag
  102.  
  103.       ELSE
  104.  
  105.         DO _OpenDbf WITH lc_catdbf, 1, pl_useok
  106.  
  107.       ENDIF   && ll_isview
  108.  
  109.     ELSE                                && DBF already in use, so...
  110.  
  111.       IF .NOT. ll_isview
  112.  
  113.         *-- Look for the DBF file associated with the SCR file
  114.         IF ALIAS() <> lc_catdbf
  115.  
  116.           ll_usedbf = .F.
  117.           ll_esc = .F.
  118.  
  119.           IF .NOT. pl_scbatt
  120.  
  121.             DO _CatWhich WITH lc_catdbf + ".DBF", ;
  122.                               ll_usedbf, ;
  123.                               ll_esc
  124.  
  125.           ELSE
  126.  
  127.             ll_usedbf = .T.
  128.  
  129.           ENDIF
  130.  
  131.           IF .NOT. ll_esc               && If the user did not press esc
  132.  
  133.             pl_useok = .T.              && Set the open flag
  134.  
  135.             IF ll_usedbf                && If the DBF was selected
  136.  
  137.               DO _OpenDbf WITH lc_catdbf, 1, pl_useok
  138.  
  139.             ENDIF
  140.  
  141.           ELSE
  142.  
  143.             pl_useok = .F.
  144.  
  145.           ENDIF
  146.  
  147.         ELSE                            && Alias and current DBF() match
  148.  
  149.           pl_useok = .T.                && Correct DBF already in use
  150.  
  151.         ENDIF
  152.  
  153.       ELSE                              && Related catalog file is a view
  154.  
  155.         *-- Put the view in use if needed
  156.         IF _FileRoot( SET("VIEW") ) <> lc_catdbf
  157.  
  158.           ll_usedbf = .F.
  159.           ll_esc = .F.
  160.           DO _CatWhich WITH lc_catdbf + "." + _FileType( lc_dbf2use ) , ;
  161.                             ll_usedbf, ;
  162.                             ll_esc
  163.           IF .NOT. ll_esc               && If the user did not press esc
  164.  
  165.             IF ll_usedbf                && If the view was selected
  166.               SET VIEW TO ( lc_dbf2use )&& Open the view
  167.             ENDIF
  168.  
  169.             pl_useok = .T.              && Set the use ok flag true
  170.  
  171.           ENDIF
  172.  
  173.         ELSE
  174.  
  175.           pl_useok = .T.
  176.  
  177.         ENDIF
  178.  
  179.       ENDIF   && Not a QBE file
  180.  
  181.     ENDIF   && DBF is not in use and not a new screen
  182.  
  183.   ELSE    && No catalog match
  184.  
  185.     IF .NOT. ISBLANK( ALIAS() )
  186.       pl_useok = .T.                      && Use the current view
  187.     ENDIF
  188.  
  189.   ENDIF   && There was a catalog match
  190.  
  191. RETURN
  192. *-- EOP:  _fxUseIt WITH pc_file, pl_useok
  193. *'-------------------------------------------------------------------------
  194. *' $Log:   E:/test/sysproc/doc/_fxuseit.prv  $
  195. *'-------------------------------------------------------------------------
  196.  
  197.  
  198.